<?php
namespace app\command;


use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use app\common\service\GuguService;


class SchoolLine extends Command
{
    protected function configure()
    {
        $this->setName('school_line')->setDescription('Your command description');
    }

    protected function execute(Input $input, Output $output)
    {
		// Db::name('school')->field('college_name') -> chunk(100, function($users) {
		   // foreach($users as $user)  {
				
			// }
		// });
		$year = 2024;
		$list = Db::name('school')->field('college_name')->order('id asc')->select();
		foreach($list as $key=>$school){
			$page = 1;
			$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>100,'searchtype'=>'COLLEGENAME','keyword'=>$school['college_name'],'year'=>$year,'keywordstrict'=>'true']);
			if($result[0] != 200){
			   setLog('school_line','没有数据：'.$school['college_name']);
			   continue;
			}
			$page_total = ceil($result[1][0]['DataTotalCount']/100);
			for($page=1;$page<=$page_total;$page++){
				$result = GuguService::make('/metadata/ceecollegeline',['appkey'=>'UZ8X3YJWLFJWJKY28U63K8YFUTQZX4RD','pageindex'=>$page,'pagesize'=>100,'searchtype'=>'COLLEGENAME','keyword'=>$school['college_name'],'year'=>$year]);
				$dataM = [];
				$nowtime = time();
				if(!empty($result[1][1])){
					foreach($result[1][1] as $k=>$v){
						$dataM[] = ['province'=>$v['Province'],'school_uuid'=>$v['SchoolUUID'],'college_name'=>$v['CollegeName'],'year'=>$v['Year'],'highest_score'=>$v['HighestScore'],'average_score'=>$v['AverageScore'],'lowest_score'=>$v['LowestScore'],'lowest_rank'=>$v['LowestRank'],'provincial_controlLine'=>$v['ProvincialControlLine'],'enrollment_type'=>$v['EnrollmentType'],'selection_level'=>$v['SelectionLevel'],'admission_batch'=>$v['AdmissionBatch'],'type_name'=>$v['TypeName'],'course_selection'=>$v['CourseSelection'],
						'course_selection_name'=>$v['CourseSelectionName'],'subject_group'=>$v['SubjectGroup'],
						'school_type'=>$v['SchoolType'],'school_in_city'=>$v['SchoolInCity'],
						'is985'=>$v['Is985'],
						'is211'=>$v['Is211'],'is_dual_class'=>$v['IsDualClass'],'cover_image'=>$v['CoverImage'],
						'create_time'=>$nowtime,'update_time'=>$nowtime];
					}
				}
				if(!empty($dataM)){
					$flag = Db::name('school_line_new')->insertAll($dataM);
					if(!$flag){
						setLog('school_line','插入出错：'.$school['college_name'].$page.'页');
					}
				}
			}
			setLog('school_line','拉取成功：'.$school['college_name']);
		}
		
		setLog('school_line','执行完毕');exit();
		
    }


}
